<?php
namespace App\Http\Controllers\Index;

use App\Models\Admin\AreaStation;
use App\Models\Admin\CollPlace;
use App\Models\Common\CollTown;
use App\Models\Common\CollArea;
use App\Models\Common\CollOption;
use App\Models\Common\CollPosition;

use App\Models\Common\English\EnCollArea;
use App\Models\Common\English\EnCollOption;
use App\Models\Common\English\EnCollPosition;
use App\Models\Personal\Interview;
use App\Models\XS\JobXS;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Style, DB, Site, Config;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Personal\BrowseJob;
use App\Models\Personal\BrowseCompany;
use App\Models\Company\CompanyJob;
use App\Models\Company\CompanyBasic;
use App\Models\Company\CompanyPhoto;
use App\Models\Company\CompanyContact;
use App\Models\Company\CompanyDepartment;
use App\Models\Company\CompanyUser;
use App\Models\Personal\ResumeSend;
use App\Models\Personal\Resume;
use App\Models\Personal\Favorites;
use Cache;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;

class JobController extends CommonController{

    /**
     * 二维数组查询值是否存在
     * @param $value
     * @param $array
     * @param $key
     * @return bool
     */
    protected function inToArray($value, $array, $key){
        foreach($array as $k => $v){
            if($v[$key] == $value){
                return true;
            }
        }
        return false;
    }

    /**
     * 找工作
     * @param Request $request
     * @return mixed
     */
    public function job(Request $request){
        //福利
        $welfares = [['value' => '', 'text' => '不限'], ['value' => 1, 'text' => '五险'], ['value' => 2, 'text' => '公积金'],
            ['value' => 3, 'text' => '包吃'], ['value' => 4, 'text' => '包住'], ['value' => 5, 'text' => '双休'],
            ['value' => 6, 'text' => '带薪年假'], ['value' => 7, 'text' => '交通补贴'], ['value' => 8, 'text' => '年终奖']];
        //薪资
        $salarys = [['value' => '', 'salary' => ['', ''], 'text' => '不限'],
            ['value' => 1, 'salary' => ['0', '2000'], 'text' => '2000以下'],
            ['value' => 2, 'salary' => ['2000', '4000'], 'text' => '2000-4000'],
            ['value' => 3, 'salary' => ['4000', '6000'], 'text' => '4000-6000'],
            ['value' => 4, 'salary' => ['6000', '8000'], 'text' => '6000-8000'],
            ['value' => 5, 'salary' => ['8000', '10000'], 'text' => '8000-1万'],
            ['value' => 6, 'salary' => ['10000', '15000'], 'text' => '1万-1.5万'],
            ['value' => 7, 'salary' => ['15000', '20000'], 'text' => '1.5万-2万'],
            ['value' => 8, 'salary' => ['20000', '30000'], 'text' => '2万-3万'],
            ['value' => 9, 'salary' => ['30000', '40000'], 'text' => '3万-4万'],
            ['value' => 10, 'salary' => ['40000', '50000'], 'text' => '4万-5万'],
            ['value' => 11, 'salary' => ['50000', '1000000'], 'text' => '5万以上']];
        //接收值
        $input = $request->only(
            'jobsort1', 'jobsort2', 'jobsort3', 'jobsort4', 'jobsort5',
            'jobarea1', 'jobarea2', 'jobarea3', 'jobarea4', 'jobarea5',
            'industry1', 'industry2', 'industry3', 'industry4', 'industry5',
            'sex', 'age', 'trade', 'work_year', 'education', 'keyword', 'keyword_type', 'release_date', 'welfare',
            'salary',
            'graduate', 'anxious', 'brandcompany', 'map_show', 'part_status'
        );
        //地区搜索
        $webareacode = Site::get('webareacode');//读取地区编码
        if(substr($webareacode, -2, 2) != '00'){
            $areas = CollTown::getTown($webareacode);//返回乡镇地区
        }else{
            $areas = CollArea::getCity($webareacode);//返回县级市地区
        }
        array_unshift($areas, ['value' => '', 'text' => "不限"]);
        if(!empty($request->location1)){
            $request->jobarea1 = $request->location1;//解决个人后台input冲突临时方案
            $input['jobarea1'] = $request->location1;
        }
        $map_show = !empty($request->map_show) ? '1' : '';
        $jobTitle = empty($request->map_show) ? '找工作' : '附近工作';
        if(!empty($map_show)){
            //map地图
            $positon = $request->position;
            if(!empty($positon)){
                if(session('mypos') != $positon){
                    session()->put('mypos', $positon);
                }
            }
            if(!empty(session('mypos'))){
                $mypos = explode(',', session('mypos'));
                $_lng = $mypos[0];
                $_lat = $mypos[1];
                $curr_position = $mypos[2];
                $mypos = session('mypos');
                $set_seesion = 'yes';
            }else{
                $curr_position = Site::get('address');
                $mypos = Site::get('longitude') . ',' . Site::get('latitude') . ',' . Site::get('address');
                $set_seesion = 'no';
            }

            if(!empty($positon)){
                if(session('mypos') != $positon){
                    session()->put('mypos', $positon);
                }
            }
//            dd($_lng);
            //经度纬度
            $_lng = !empty($_lng) ? $_lng : Site::get('longitude');
            $_lat = !empty($_lat) ? $_lat : Site::get('latitude');
            $juli = DB::raw("(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(" . $_lat . "-" . env('DB_PREFIX') . "t2.latitude)/360),2)+COS(PI()*" .
                $_lat . "/180)* COS(" . env('DB_PREFIX') . "t2.latitude * PI()/180)*POW(SIN(PI()*(" . $_lng . "-" . env('DB_PREFIX') . "t2.longitude)/360),2)))) as juli");
            $order1 = DB::raw('case when juli is null then 1 else 0 end ,juli');
            $orderBy1 = 'asc';
            $order2 = "id";
            $orderBy2 = 'desc';
            //为xunsearch讯搜加上去的
            $request->query->set('longitude', $_lng);
            $request->query->set('latitude', $_lat);
        }else{
            $juli = "t2.contacts";
            $order1 = "t1.updatetime";
            $order2 = "t1.id";
            $orderBy1 = 'desc';
            $orderBy2 = 'desc';
        }

        //去空
        $pageInput = arrayFilter($input);
        $this->urlArray = $pageInput;
        /**_______________选择搜索引擎_________________***/
        //处理数据查询
        if(Site::get('xsOpen') && (!empty($request->keyword) || !empty($request->jobsort1))){
            $company_job = $this->xunSearch($request, $welfares, $salarys);
            if(!$company_job->total()) $company_job = $this->sqlSearch($request, $welfares, $salarys, $juli, $order1, $order2, $orderBy1, $orderBy2, $map_show);
        }else{
            $company_job = $this->sqlSearch($request, $welfares, $salarys, $juli, $order1, $order2, $orderBy1, $orderBy2, $map_show);
        }
        $page = $company_job->appends($pageInput)->links();//分页链接
        /**_______________选择搜索引擎结束*******************/

        //生成地区链接数组
        $checkarray = array($request->jobarea1, $request->jobarea2, $request->jobarea3, $request->jobarea4, $request->jobarea5);

        foreach($areas as $k => $v){
            $area[$k]['url'] = urlPagePack($pageInput, ['jobarea1' => $v['value'], 'jobarea2' => null,
                'jobarea3' => null, 'jobarea4' => null, 'jobarea5' => null]);
            $area[$k]['text'] = $v['text'];
            if(in_array($v['value'], $checkarray) and $v['value'] != ''){
                $area[$k]['check'] = 1;
            }else{
                if($v['value'] == '' and $request->jobarea1 == ''){
                    $area[$k]['check'] = 1;
                }else{
                    $area[$k]['check'] = 0;
                }
            }
        }
        foreach($checkarray as $k => $v){
            if($v != null and !$this->inToArray($v, $areas, 'value')){
                $area[] = array(
                    'url' => urlPagePack($pageInput, ['jobarea1' => $v, 'jobarea2' => null,
                        'jobarea3' => null, 'jobarea4' => null, 'jobarea5' => null]),
                    'text' => CollArea::getAreaName($v),
                    'check' => 1,
                );
            }
        }
        $optionsurl['jobarea'] = urlPagePack($pageInput, ['jobarea1' => null, 'jobarea2' => null,
            'jobarea3' => null, 'jobarea4' => null, 'jobarea5' => null]);

        //福利链接数组成生
        $welfare = array();
        foreach($welfares as $k => $v){
            $welfare[$k]['url'] = urlPagePack($pageInput, ['welfare' => $v['value']]);
            $welfare[$k]['text'] = $v['text'];
            $welfare[$k]['value'] = $v['value'];
        }

        //月薪
        foreach($salarys as $k => $v){
            $salary[$k]['url'] = urlPagePack($pageInput, ['salary' => $v['value']]);
            $salary[$k]['text'] = $v['text'];
            $salary[$k]['value'] = $v['value'];
        }
        //工地岗位转中文
        $jobsort1 = ($request->jobsort1) ? CollPosition::getPosName($request->jobsort1) : '';
        $jobsort2 = ($request->jobsort2) ? CollPosition::getPosName($request->jobsort2) : '';
        $jobsort3 = ($request->jobsort3) ? CollPosition::getPosName($request->jobsort3) : '';
        $jobsort4 = ($request->jobsort4) ? CollPosition::getPosName($request->jobsort4) : '';
        $jobsort5 = ($request->jobsort5) ? CollPosition::getPosName($request->jobsort5) : '';
        $cninput['jobsort'] = trim($jobsort1 . '+' . $jobsort2 . '+'
            . $jobsort3 . '+' . $jobsort4 . '+' . $jobsort5, '+');
        $optionsurl['jobsort'] = urlPagePack($pageInput, ['jobsort1' => null, 'jobsort2' => null,
            'jobsort3' => null, 'jobsort4' => null, 'jobsort5' => null]);
        //行业
        $industry1 = ($request->industry1) ? CollOption::getOptionName($request->industry1, 'industry') : '';
        $industry2 = ($request->industry2) ? CollOption::getOptionName($request->industry2, 'industry') : '';
        $industry3 = ($request->industry3) ? CollOption::getOptionName($request->industry3, 'industry') : '';
        $industry4 = ($request->industry4) ? CollOption::getOptionName($request->industry4, 'industry') : '';
        $industry5 = ($request->industry5) ? CollOption::getOptionName($request->industry5, 'industry') : '';
        $cninput['industry'] = trim($industry1 . '+' . $industry2 . '+' . $industry3 .
            '+' . $industry4 . '+' . $industry5, '+');
        $optionsurl['industry'] = urlPagePack($pageInput, ['industry1' => null, 'industry2' => null,
            'industry3' => null, 'industry4' => null, 'industry5' => null]);
        //工作经验
        $optionsurl['work_year'] = urlPagePack($pageInput, ['work_year' => null]);
        //学历
        $optionsurl['education'] = urlPagePack($pageInput, ['education' => null]);
        //急招
        $optionsurl['anxious'] = urlPagePack($pageInput, ['anxious' => null]);
        //名企
        $optionsurl['brandcompany'] = urlPagePack($pageInput, ['brandcompany' => null]);
        //搜索关键字
        $optionsurl['keyword'] = urlPagePack($pageInput, ['keyword' => null]);
        //begin--对地区进行一次性查询
        $locationAreaArr = [];//6位数的区域id数组
        $locationTownArr = [];//8位数的乡镇id数组
        foreach($company_job as $k => $v){
            for($i = 1; $i < 6; $i++){
                if(strlen($v->{'location' . $i}) == 6){
                    $locationAreaArr[] = $v->{'location' . $i};
                }elseif(strlen($v->{'location' . $i}) == 8){
                    $locationTownArr[] = $v->{'location' . $i};
                }
            }
        }
        for($i = 1; $i < 6; $i++){
            if(strlen($request->{'jobarea' . $i}) == 6){
                $locationAreaArr[] = $request->{'jobarea' . $i};
            }elseif(strlen($request->{'jobarea' . $i}) == 8){
                $locationTownArr[] = $request->{'jobarea' . $i};
            }
        }
        $locationAreaArr = array_values(array_unique($locationAreaArr));
        $locationTownArr = array_values(array_unique($locationTownArr));
        $AreaNameArr = CollArea::whereIn('cid', $locationAreaArr)->pluck('name', 'cid')->toArray();
        $TownNameArr = CollTown::whereIn('cid', $locationTownArr)->pluck('name', 'cid')->toArray();
        $locationNameArr = $AreaNameArr + $TownNameArr;
        /**end--对地区进行一次性查询**/

        //压入中文到数组
//        $cnoption['jobarea1'] = (strlen($request->jobarea1) == 8) ? CollTown::getTownName($request->jobarea1) : CollArea::getAreaName($request->jobarea1);
//        $cnoption['jobarea2'] = (strlen($request->jobarea2) == 8) ? CollTown::getTownName($request->jobarea2) : CollArea::getAreaName($request->jobarea2);
//        $cnoption['jobarea3'] = (strlen($request->jobarea3) == 8) ? CollTown::getTownName($request->jobarea3) : CollArea::getAreaName($request->jobarea3);
//        $cnoption['jobarea4'] = (strlen($request->jobarea4) == 8) ? CollTown::getTownName($request->jobarea4) : CollArea::getAreaName($request->jobarea4);
//        $cnoption['jobarea5'] = (strlen($request->jobarea5) == 8) ? CollTown::getTownName($request->jobarea5) : CollArea::getAreaName($request->jobarea5);
        $cnoption['jobarea1'] = empty($locationNameArr[$request->jobarea1]) ? '' : $locationNameArr[$request->jobarea1];
        $cnoption['jobarea2'] = empty($locationNameArr[$request->jobarea2]) ? '' : $locationNameArr[$request->jobarea2];
        $cnoption['jobarea3'] = empty($locationNameArr[$request->jobarea3]) ? '' : $locationNameArr[$request->jobarea3];
        $cnoption['jobarea4'] = empty($locationNameArr[$request->jobarea4]) ? '' : $locationNameArr[$request->jobarea4];
        $cnoption['jobarea5'] = empty($locationNameArr[$request->jobarea5]) ? '' : $locationNameArr[$request->jobarea5];

        $cnoption['jobarea'] = trim($cnoption['jobarea1'] . '+' . $cnoption['jobarea2'] . '+' . $cnoption['jobarea3'] .
            '+' . $cnoption['jobarea4'] . '+' . $cnoption['jobarea5'], '+');

        if(!empty($welfares[$request->welfare])) $cnoption['welfare'] = $welfares[$request->welfare]['text'];//福利
        if(!empty($salary[$request->salary])) $cnoption['salary'] = $salary[$request->salary]['text'];//月薪

        $cnoption['jobsort1'] = $jobsort1;
        $cnoption['jobsort2'] = $jobsort2;
        $cnoption['jobsort3'] = $jobsort3;
        $cnoption['jobsort4'] = $jobsort4;
        $cnoption['jobsort5'] = $jobsort5;

        $cnoption['jobsort'] = $cninput['jobsort'];
        //行业
        $cnoption['industry1'] = $industry1;
        $cnoption['industry2'] = $industry2;
        $cnoption['industry3'] = $industry3;
        $cnoption['industry4'] = $industry4;
        $cnoption['industry5'] = $industry5;

        $cnoption['industry'] = $cninput['industry'];

        $cnoption['work_year'] = CollOption::getOptionName($request->work_year, 'work_year');
        $cnoption['education'] = CollOption::getOptionName($request->education, 'education');

        $cnoption['anxious'] = '';
        $cnoption['brandcompany'] = '';
        $cnoption['keyword_type'] = '';
        $cnoption['keyword'] = msubstr($input['keyword'], 0, 10);
        $cnoption['page'] = '';

        //生成去除条件链接
        $del_list = array();
        foreach($pageInput as $key => $value){
            $ikey = substr($key, 0, -1);
            if($ikey != 'jobarea' and $ikey != 'jobsort' and $ikey != 'industry'){
                if(!empty($cnoption[$key])){
                    $del_list[] = array('text' => $cnoption[$key], 'url' => urlPagePack($pageInput, [$key => null]));
                }
            }else{
                if(substr($key, -1, 1) == 1){
                    $key1 = $ikey . '1';
                    $key2 = $ikey . '2';
                    $key3 = $ikey . '3';
                    $key4 = $ikey . '4';
                    $key5 = $ikey . '5';
                    $del_list[] = array('text' => msubstr($cnoption[$ikey], 0, 10), 'url' => urlPagePack($pageInput,
                        [$key1 => null, $key2 => null, $key3 => null, $key4 => null, $key5 => null]));
                }
            }
        }

        foreach($company_job as $k => $v){
            //急聘
            if($v->urgent > date('Y-m-d H:i:s', strtotime('-5 day'))){
                $v->urgent = 1;
            }else{
                $v->urgent = 0;
            }
            if(empty($v->salary_above) and empty($v->salary_below)){
                $v->salary_above = '面议';
            }elseif(!empty($v->salary_above) and empty($v->salary_below)){
                $v->salary_above = $this->numTostring($v->salary_above);
            }elseif(empty($v->salary_above) and !empty($v->salary_below)){
                $v->salary_above = $this->numTostring($v->salary_below);
            }else{
                $v->salary_above = $this->numTostring($v->salary_above) . '-' . $this->numTostring($v->salary_below);
            }
            $v->location1 = !empty($locationNameArr[$v->location1]) ? $locationNameArr[$v->location1] : '';
            $v->location2 = !empty($locationNameArr[$v->location2]) ? $locationNameArr[$v->location2] : '';
            $v->location3 = !empty($locationNameArr[$v->location3]) ? $locationNameArr[$v->location3] : '';
            $v->location4 = !empty($locationNameArr[$v->location4]) ? $locationNameArr[$v->location4] : '';
            $v->location5 = !empty($locationNameArr[$v->location5]) ? $locationNameArr[$v->location5] : '';
            //地区
            $v->location = $v->location1 . ' ' . $v->location2 . ' ' . $v->location3 . ' ' . $v->location4 . ' ' . $v->location5;

            if(trim($v->location) == ''){
                $v->location = "地区不限";
            }

            $v->work_year = CollOption::getOptionName($v->work_year, 'work_year');
            $v->education = CollOption::getOptionName($v->education, 'education');
            $v->industry = str_limit(CollOption::getOptionName($v->industry, 'industry'), 36);
            $fare = ''; //福利
            if(!empty($v->welfare)){
                foreach(explode(',', $v->welfare) as $welfare_value){
                    $fare .= "<span>$welfare_value</span>";
                }
            }
            $v->welfare = $fare;
            $v->updatetime = substr($v->updatetime, 0, 10);
            $v->employee_num = CollOption::getOptionName($v->employee_num, 'employee_num');

            //附近工作
            if(!empty($map_show)){
                $juli = ($v->juli) * 1000;
                if($juli >= 1000){
                    $juli = ceil($juli / 100) * 100;
                    $v->juli = ($juli / 1000) . '公里';
                }else if($juli < 1000 && $juli >= 0){
                    $v->juli = ceil($juli) . '米';
                }else{
                    $v->juli = '坐标未获取';
                }
            }
        }
        //这些公司正在招==>推荐工作
        /**_______________选择搜索引擎_________________***/
        //处理数据查询
        if(Site::get('xsOpen') && (!empty($request->keyword))){
            $recommendedjob = $this->xunRecommendedSearch($request);
            if(!$company_job->total()) $recommendedjob = $this->sqlRecommendedSearch($request);
        }else{
            $recommendedjob = $this->sqlRecommendedSearch($request);
        }
        /**_______________选择搜索引擎结束*******************/

        foreach($recommendedjob as $k => $v){
            if(empty($v->salary_above) and empty($v->salary_below)){
                $v->salary_above = '面议';
            }elseif(!empty($v->salary_above) and empty($v->salary_below)){
                $v->salary_above = $this->numTostring($v->salary_above);
            }elseif(empty($v->salary_above) and !empty($v->salary_below)){
                $v->salary_above = $this->numTostring($v->salary_below);
            }else{
                $v->salary_above = $this->numTostring($v->salary_above) . '-' . $this->numTostring($v->salary_below);
            }

            //logo
            if(!empty($v->logo)){
                $v->logo = "<img src='" . asset('upload/companylogo/' . $v->logo) . "'>";
            }else{
                $v->logo = "<img src='" . asset('/default/images/index/default_company_img.jpg') . "'>";
            }
        }
        //是不是附近工作
        $place = array();
        if(!empty($map_show)){
            if(Cache::has('collPlace')){
                $place = Cache::get('collPlace');
            }else{
                $CollPlace = CollPlace::all();//获取地标的位置
                $getSiteCity = CollArea::getSiteCity();//获取当前站点的信息
                foreach($getSiteCity as $k => $v){
                    $place[$k]['city'] = $v['text'];
                    foreach($CollPlace as $vv){
                        if($v['value'] == $vv->pid){
                            $place[$k]['place'][] = $vv;
                        }
                    }
                }
                Cache::forever('collPlace', $place);
            }
        }
        //设置标题
        $area_name = !empty($request->jobarea1) ? $cnoption['jobarea1'] : Site::get('area_name');
        $keyword = !empty($request->jobsort1) ? $jobsort1 : $input['keyword'];
        $job_search = (strlen($keyword) > 0) ? $area_name . $keyword . '招聘|' : '';
        //地区分站
        return Style::view('index.job', compact('company_job', 'page', 'area', 'welfare', 'salary', 'optionsurl',
            'del_list', 'input', 'cninput', 'del_list', 'recommendedjob',
            'place', 'map_show', 'jobTitle', 'curr_position', 'mypos', 'set_seesion', 'job_search'
        ));

    }

    /** 迅搜搜索
     * @param $request
     * @return \Illuminate\Pagination\LengthAwarePaginator
     */
    public function xunSearch($request, $welfares, $salarys){
        //查询条件
        $q = $request->all();

        //福利
        if(!empty($request->welfare)) $q['welfare'] = $welfares[$request->welfare]['text'];

        //薪资范围
        if(!empty($request->salary)){
            $q['salary_above'] = $salarys[$request->salary]['salary'][0];
            $q['salary_below'] = $salarys[$request->salary]['salary'][1];
        }

        //工作地点、所属岗位、行业分类
        $jobarea = [];//工作地点
        $jobsort = [];//所属岗位
        $industry = [];//行业分类
        for($i = 1; $i <= 5; $i++){
            $area = $request->input('jobarea' . $i);
            $sort = $request->input('jobsort' . $i);
            $dustry = $request->input('industry' . $i);
            if(!empty($area)){
                $jobarea[] = $area;
            }
            if(!empty($sort)){
                $jobsort[] = $sort;
            }
            if(!empty($dustry)){
                $industry[] = $dustry;
            }
        }

        //关键字
        unset($q['keyword']);
        if(!empty($request->keyword)){
            if($request->keyword_type == 2){
                $q['job_title'] = $request->keyword;
                unset($q['keyword']);
            }elseif($request->keyword_type == 3){
                $q['company_name'] = $request->keyword;
                unset($q['keyword']);
            }else{
                $q['keyword'] = $request->keyword;
            }
        }

        $q['jobarea'] = $jobarea;
        $q['jobsort'] = $jobsort;
        $q['industry'] = $industry;

        $jobxs = new JobXS();
        //查询页码
        $page = $request->input('page', 1);
        if($page > 200) $page = 200;
        //搜索(参数:搜索条件,第几页,一页个数,获取总数,是否按照时间排序)
        $arr = $jobxs->searchJob($q, $page, 20, true);

        //分页并返回
        return $this->pageInfo($arr['data'], $arr['total'], $request);
    }

    /** 数据库搜索
     * @param $request
     * @return mixed
     */
    public function sqlSearch($request, $welfares, $salarys, $juli, $order1, $order2, $orderBy1, $orderBy2, $map_show){
        $company_job = DB::table('company_job as t1')
            ->join('company_basic as t2', 't1.com_id', '=', 't2.id')
            //获取字段
            ->select(
                't1.id', 't1.com_id', 't1.job_title', 't1.industry',
                't1.job_category1', 't1.job_category2', 't1.job_category3', 't1.job_category4', 't1.job_category5',
                't1.location1', 't1.location2', 't1.location3', 't1.location4', 't1.location5',
                't1.recruiting_num', 't1.salary_above', 't1.salary_below', 't1.description', 't1.welfare', 't1.part_status',
                't1.education', 't1.work_year', 't1.age_above', 't1.age_below', 't1.gender', 't1.updatetime',
                't2.company_name', 't2.region', 't2.industry', 't2.address', 't2.employee_num', 't1.urgent',
                't2.longitude', 't2.latitude', $juli
            )
            //职位显示审核通过的
            ->where('t1.job_status', '1')
            //岗位
            ->where(function($query) use ($request){
                for($i = 1; $i <= 5; $i++){
                    if(!empty($request->{'jobsort' . $i}))
                        $query->orWhere('t1.job_category1', '=', $request->{'jobsort' . $i})
                            ->orWhere('t1.job_category2', '=', $request->{'jobsort' . $i})
                            ->orWhere('t1.job_category3', '=', $request->{'jobsort' . $i})
                            ->orWhere('t1.job_category4', '=', $request->{'jobsort' . $i})
                            ->orWhere('t1.job_category5', '=', $request->{'jobsort' . $i});
                    else break;
                }
            })
            //工作地点
            ->where(function($query) use ($request){
                $city = [];
                for($i = 1; $i <= 5; $i++){
                    if(!empty($request->input('jobarea' . $i))){
                        $query->orWhere('t1.location1', '=', $request->{'jobarea' . $i})
                            ->orWhere('t1.location2', '=', $request->{'jobarea' . $i})
                            ->orWhere('t1.location3', '=', $request->{'jobarea' . $i})
                            ->orWhere('t1.location4', '=', $request->{'jobarea' . $i})
                            ->orWhere('t1.location5', '=', $request->{'jobarea' . $i});
                        $city[] = substr($request->input('jobarea' . $i), 0, 4) . '00';
                    }else{
                        break;
                    }
                }
                if(count($city) > 0){
                    $city = array_unique($city);
                    foreach($city as $v){
                        $query->orWhere('t1.location1', '=', $v)
                            ->orWhere('t1.location2', '=', $v)
                            ->orWhere('t1.location3', '=', $v)
                            ->orWhere('t1.location4', '=', $v)
                            ->orWhere('t1.location5', '=', $v);
                    }
                }
            })
            //所属行业
            ->where(function($query) use ($request){
                for($i = 1; $i <= 5; $i++){
                    if(!empty($request->input('industry' . $i))){
                        $query->orWhere('t1.industry', '=', $request->input('industry' . $i));
                    }else break;
                }
            })
            //福利
            ->where(function($query) use ($request, $welfares){
                if(!empty($request->welfare)) $query->where('t1.welfare', 'like', "%" . $welfares[$request->welfare]['text'] . "%");
            })
            //月薪要求(按起薪来搜索)
            ->where(function($query) use ($request, $salarys){
                if(!empty($request->salary)){
                    $query->where('t1.salary_above', '>=', $salarys[$request->salary]['salary'][0])
                        ->where('t1.salary_above', '<=', $salarys[$request->salary]['salary'][1]);
                }
            })
            //性别要求
            ->where(function($query) use ($request){
                if(!empty($request->sex)) $query->where('t1.gender', '=', $request->sex);
            })
            //年龄要求 当前所选大于或者等于年龄以上的
            ->where(function($query) use ($request){
                if(!empty($request->age)){
                    $query->where('t1.age_above', '<=', $request->age)->where(function($q) use ($request){
                        $q->where('t1.age_below', '>=', $request->age)->orWhere('t1.age_below', 0);
                    });
                }
            })
            //学历要求
            ->where(function($query) use ($request){
                if(!empty($request->education)) $query->where('t1.education', '>=', $request->education);
            })
            //工作经验 当前所选工作经验以上
            ->where(function($query) use ($request){
                if(!empty($request->work_year)) $query->where('t1.work_year', '>=', $request->work_year);
            })
            //关键字
            ->where(function($query) use ($request){
                if(!empty($request->keyword)){
                    if($request->keyword_type == '2'){
                        $query->where('t1.job_title', 'like', '%' . $request->keyword . '%');
                    }elseif($request->keyword_type == '3'){
                        $query->where('t2.company_name', 'like', '%' . $request->keyword . '%');
                    }else{
                        $query->where('t1.job_title', 'like', '%' . $request->keyword . '%')
                            ->orWhere('t2.company_name', 'like', '%' . $request->keyword . '%');
                    }
                }
            })
            //发布日期
            ->where(function($query) use ($request){
                if(!empty($request->release_date)){
                    //获取选中的多少时间内
                    $ctime = date("Y-m-d H:i:s", strtotime("-" . $request->release_date . "day"));
                    $query->where('t1.updatetime', '>=', $ctime);
                }
            })
            //急招
            ->where(function($query) use ($request){
                if(!empty($request->anxious)){
                    //获取选中的多少时间内
                    $query->where('t1.urgent', '>=', date("Y-m-d H:i:s", strtotime(' -5 day', time())));
                }
            })
            //附近工作只找15天内的
            ->where(function($query) use ($request, $map_show){
                if(!empty($map_show)){
                    //获取选中的多少时间内
                    $query->where('t1.updatetime', '>=', date("Y-m-d H:i:s", strtotime(' -15 day', time())));
                }
            })
            //实习
            ->where(function($query) use ($request){
                if(!empty($request->part_status)) $query->where('t1.part_status', '=', $request->part_status);
            });

        $count = $company_job->count();

        $company_job = $company_job->orderBy($order1, $orderBy1)
            ->orderBy($order2, $orderBy2)
            ->skip($this->getSkip($request->page))->take(20)->get();

        return $this->pageInfo($company_job, $count, $request);
    }

    /** 迅搜搜索==>这些公司正在招==>推荐工作
     * @param $request
     * @return \Illuminate\Pagination\LengthAwarePaginator
     */
    public function xunRecommendedSearch($request){
        //查询条件
        $q = [];
        //关键字
        if(!empty($request->keyword)){
            if($request->keyword_type == 2){
                $q['job_title'] = $request->keyword;
            }elseif($request->keyword_type == 3){
                $q['company_name'] = $request->keyword;
            }else{
                $q['keyword'] = $request->keyword;
            }
        }

        $jobxs = new JobXS();
        //搜索(参数:搜索条件,第几页,一页个数,获取总数,是否按照时间排序)
        $arr = $jobxs->searchJob($q, 1, 7, false);

        //分页并返回
        return $arr['data'];
    }

    /** 数据库搜索==>这些公司正在招==>推荐工作
     * @param $request
     * @return mixed
     */
    public function sqlRecommendedSearch($request){
        $recommendedjob = DB::table('company_job as a')//join操作
        ->join('company_basic as b', 'b.id', '=', 'a.com_id')
            ->select('a.com_id', 'a.id', 'a.job_title', 'a.salary_above', 'a.salary_below', 'b.company_name', 'b.logo')
            ->where("a.job_status", 1)//发布中的职位
            //->where("urgent", ">=", date("Y-m-d H:i:s", strtotime(' -5 day', time())))
            //关键字
            ->where(function($query) use ($request){
                if(!empty($request->keyword)){
                    if($request->keyword_type == '1'){
                        //全文搜索时？？？？
                        $query->where('a.job_title', 'like', '%' . $request->keyword . '%')
                            ->orWhere('b.company_name', 'like', '%' . $request->keyword . '%');
                    }elseif($request->keyword_type == '2'){
                        $query->where('a.job_title', 'like', '%' . $request->keyword . '%');
                    }elseif($request->keyword_type == '3'){
                        $query->where('b.company_name', 'like', '%' . $request->keyword . '%');
                    }
                }
            })
            ->orderBy("urgent", "desc")
            ->orderBy('a.id', 'desc')
            ->take(8)
            ->get();
        return $recommendedjob;
    }

    /**
     * 英文版职位浏览
     * @param $jobid
     * @return mixed
     */
    public function english($jobinfo){
        //个人用户登录
        $user = auth()->guard('personal')->user();
        $jobid = $jobinfo->id;//当前工作页面详情

        //查找最近登录时间
        $companyUser = CompanyUser::select('last_login_time', 'viptime')->where('uid', $jobinfo->uid)->first();
        $last_login_time = $this->timediff($companyUser->last_login_time);//timeTranx
        //计算企业回复率
        $allResume = ResumeSend::where("company_uid", $jobinfo->uid)->where("com_id", $jobinfo->com_id)->count();
        $alreadyToCheckResume = ResumeSend::where("company_uid", $jobinfo->uid)->where("com_id", $jobinfo->com_id)->where("status", "!=", 0)->count();

        //算法*  已本看简历/所有简历
        if($allResume == 0){
            $resumeRecoveryRate = 'No';
        }else{
            $resumeRecoveryRate = (round(($alreadyToCheckResume / $allResume), 2) * 100) . '%';
        }

        $recommendedjob = CompanyJob::with(['company_basic'])
            ->where("com_id", $jobinfo->com_id)
            ->where("job_status", 1)//发布中的职位
            ->orderBy('updatetime', 'desc')->get();//推荐工作

        $right_jobinfo = CompanyJob::with(['company_basic'])->where('job_status', 1)->take(6)->orderBy("urgent", "desc")->get();//该企业其它相关招聘

        $value = $jobinfo;
        $head_title = $value->job_title;
        $company_id = $value->com_id;
        $company_uid = $value->uid;
        //工资
        if(empty($value->salary_above) and empty($value->salary_below)){
            $value->salary_above = 'Negotiable';
        }elseif(!empty($value->salary_above) and empty($value->salary_below)){
            $value->salary_above = $this->numTostring($value->salary_above);
        }elseif(empty($value->salary_above) and !empty($value->salary_below)){
            $value->salary_above = $this->numTostring($value->salary_below);
        }else{
            $value->salary_above = $this->numTostring($value->salary_above) . '-' . $this->numTostring($value->salary_below);
        }


        //返回招聘工作地点
        !empty($value->location1) ? $value->location1 = EnCollArea::getAreaName($value->location1) : $value->location1 = '';
        !empty($value->location2) ? $value->location2 = EnCollArea::getAreaName($value->location2) : $value->location2 = '';
        !empty($value->location3) ? $value->location3 = EnCollArea::getAreaName($value->location3) : $value->location3 = '';
        !empty($value->location4) ? $value->location4 = EnCollArea::getAreaName($value->location4) : $value->location4 = '';
        !empty($value->location5) ? $value->location5 = EnCollArea::getAreaName($value->location5) : $value->location5 = '';

        $value->location = $value->location1 . ' ' . $value->location2 . ' ' . $value->location3 . ' ' . $value->location4 . ' ' . $value->location5;

        if(trim($value->location) == ''){
            $value->location = "Any area";
        }

        //返回学历
        $value->education = EnCollOption::getOptionName($value->education, 'education');
        //返回行业
        $value->industry = EnCollOption::getOptionName($value->industry, 'industry');
        //返回公司性质
        $value->company_basic->comkind = EnCollOption::getOptionName($value->company_basic->comkind, 'comkind');
        //规模
        $value->company_basic->employee_num = EnCollOption::getOptionName($value->company_basic->employee_num, 'employee_num');
        //返回工作时限
        $value->work_year = EnCollOption::getOptionName($value->work_year, 'work_year');

        //返回时间
        $value->addtime = substr($value->addtime, 0, 10);

        //性别

        if($value->gender == 1){
            $sexvalue = "Man";
        }elseif($value->gender == 2){
            $sexvalue = "Woman";
        }else{
            $sexvalue = '';
        }
        $value->gender = $sexvalue;

        //年龄要求
        if(!empty($value->age_above) and !empty($value->age_below)){
            $value->age = $value->age_above . 'Year-' . $value->age_below . 'Year';
        }elseif(!empty($value->age_above) and empty($value->age_below)){
            $value->age = $value->age_above . 'Years old';
        }elseif(empty($value->age_above) and !empty($value->age_below)){
            $value->age = $value->age_below . 'Years of age';
        }else{
            $value->age = "Unlimited";
        }

        //福利
        $fare = ''; //福利

        if(!empty($value->welfare)){
            $value->welfare = explode(',', $value->welfare);
        }else{
            $value->welfare = array();
        }

        //logo
        if(!empty($value->company_basic->logo)){
            $value->logo = 'upload/companylogo/' . $value->company_basic->logo;
        }else{
            $value->logo = '/default/images/index/default_company_img.jpg';
        }
        //职位发布者信息   0 基本资料 ，1部门，2 独立联系方式，3不显示
        switch($value->contact_info){
            case "0"://0 基本资料
                $phone = explode('-', $value->company_basic->phone);
                if(!empty($phone[0]) && !empty($phone[1])){
                    if(!empty($phone[2])){
                        $value->company_basic->phone = $phone[0] . '-' . $phone[1] . '-' . $phone[2];//有分机号
                    }else{
                        $value->company_basic->phone = $phone[0] . '-' . $phone[1];//无分机号
                    }
                }

                $value->contacts = $value->company_basic->contacts;
                break;
            case "1"://1部门
                $companydepartment = CompanyDepartment::select('name', 'mobile', 'phone', 'contacts')->where('com_id', '=', $value->com_id)->take(1)->get();
                foreach($companydepartment as $cd_v){
                    $value->company_basic->mobile = $cd_v->mobile;

                    if(!empty($cd_v->phone)){
                        $phone = explode('-', $cd_v->phone);
                        if(!empty($phone[0]) && !empty($phone[1])){
                            if(!empty($phone[2])){
                                $value->company_basic->phone = $phone[0] . '-' . $phone[1] . '-' . $phone[2];//有分机号
                            }else{
                                $value->company_basic->phone = $phone[0] . '-' . $phone[1];//无分机号
                            }
                        }
                    }else{
                        $value->company_basic->phone = '';
                    }
                    $value->contacts = $cd_v->contacts;
                    $value->dePartMent = $cd_v->name;
                }

                break;
            case "2"://独立联系方式
                $companycontact = CompanyContact::select('mobile', 'phone', 'contacts')->where('job_id', '=', $value->id)->take(1)->get();
                foreach($companycontact as $cd_v){
                    $value->company_basic->mobile = $cd_v->mobile;
                    $phone = explode('-', $cd_v->phone);
                    if(!empty($phone[0]) && !empty($phone[1])){
                        if(!empty($phone[2])){
                            $value->company_basic->phone = $phone[0] . '-' . $phone[1] . '-' . $phone[2];//有分机号
                        }else{
                            $value->company_basic->phone = $phone[0] . '-' . $phone[1];//无分机号
                        }
                    }
                    $value->contacts = $cd_v->contacts;
                }
                break;
            case "3"://3不显示
                $value->company_basic->mobile = '';
                $value->company_basic->phone = '';
                $value->contacts = '保密';
                break;
        }
        $contactPerson = $value->contacts;
        $contactMobile = $value->company_basic->mobile;
        $contactPhone = $value->company_basic->phone;

        $jobinfo = $value;

        $contactButton = "companyContact ";
        //查看企业方式
        $contactHtml = ['contactPerson' => $contactPerson, 'contactMobile' => $contactMobile, 'contactPhone' => $contactPhone];
        $contactHtml = json_encode($contactHtml);

        //设置联系方式
        $contactInfo = Site::get('view_phone');
        $to_view = '';
        switch($contactInfo){
            case 1:
                $contactMobile = $this->isContactTips($value->company_basic->mobile, $contactPhone, $companyUser);
                break;
            case 2:
                if(auth()->guard('personal')->check()){
                    $contactMobile = $this->isContactTips($value->company_basic->mobile, $contactPhone, $companyUser);
                }else{
                    $contactMobile = $this->hidContact($value->company_basic->mobile, $contactPhone);
                }
                break;
            case 3:
                if(auth()->guard('personal')->check()){
                    $resume = Resume::select('id', 'resume_status')->where('uid', $user->uid)->where('default', 1)->first();//用户简历信息
                }
                if(isset($resume)){
                    $resumeSend = ResumeSend::where('job_id', $jobid)->where('personal_uid', $user->uid)->first();//有无投递记录
                    if(!empty($resumeSend)){
                        $to_view = 1;
                        $contactMobile = $this->isContactTips($value->company_basic->mobile, $contactPhone, $companyUser);
                    }else{
                        $to_view = 2;
                        $contactMobile = $this->hidContact($value->company_basic->mobile, $contactPhone);
                    }
                }else{
                    $to_view = 3;
                    $contactMobile = $this->hidContact($value->company_basic->mobile, $contactPhone);
                    // $contactMobile = "您还没创建简历,不能查看联系方式";
                }
                break;
            default:
                $contactMobile = $this->hidContact($value->company_basic->mobile, $contactPhone);
                break;
        }

        //公司相册
        $photo = CompanyPhoto::select('file', 'remark')->where('com_id', $company_id)->orderBy('updated_at', 'desc')->get()->toArray();

        //返回推荐工作====================================
        foreach($recommendedjob as $value){
            //工资
            if(empty($value->salary_above) and empty($value->salary_below)){
                $value->salary_above = 'Negotiable';
            }elseif(!empty($value->salary_above) and empty($value->salary_below)){
                $value->salary_above = $this->numTostring($value->salary_above);
            }elseif(empty($value->salary_above) and !empty($value->salary_below)){
                $value->salary_above = $this->numTostring($value->salary_below);
            }else{
                $value->salary_above = $this->numTostring($value->salary_above) . '-' . $this->numTostring($value->salary_below);
            }

            //返回招聘工作地点
            !empty($value->location1) ? $value->location1 = EnCollArea::getAreaName($value->location1) : $value->location1 = '';
            !empty($value->location2) ? $value->location2 = EnCollArea::getAreaName($value->location2) : $value->location2 = '';
            !empty($value->location3) ? $value->location3 = EnCollArea::getAreaName($value->location3) : $value->location3 = '';
            !empty($value->location4) ? $value->location4 = EnCollArea::getAreaName($value->location4) : $value->location4 = '';
            !empty($value->location5) ? $value->location5 = EnCollArea::getAreaName($value->location5) : $value->location5 = '';

            $value->location1 = $value->location1 . ' ' . $value->location2 . ' ' . $value->location3 . ' ' . $value->location4 . ' ' . $value->location5;
            $value->location1 = msubstr($value->location1, 0, 10);
            //返回学历
            !empty($value->education) ? $value->education = EnCollOption::getOptionName($value->education, 'education') : $value->education = '';

            //返回工作时限
            !empty($value->work_year) ? $value->work_year = EnCollOption::getOptionName($value->work_year, 'work_year') : $value->work_year = '';

            //返回时间
            !empty($value->addtime) ? $value->addtime = substr($value->addtime, 0, 10) : $value->addtime = '';
            //返回行业
            !empty($value->industry) ? $value->industry = EnCollOption::getOptionName($value->industry, 'industry') : $value->industry = '';

            //招聘多少人
            !empty($value->company_basic->employee_num) ? $value->employee_num = EnCollOption::getOptionName($value->company_basic->employee_num, 'employee_num') : '';


            if($value->urgent > date('Y-m-d H:i:s', strtotime('-5 day'))){
                $value->urgent = 1;
            }else{
                $value->urgent = 0;
            }
            //福利
            $fare = ''; //福利
            if(!empty($value->welfare)){
                foreach(explode(',', $value->welfare) as $welfare_value){
                    $fare .= "<i>" . e($welfare_value) . "</i>";
                }
            }
            $value->welfare = $fare;
        }

        //右边企业相关工作$right_jobinfo
        foreach($right_jobinfo as $rv){
            //工资
            if(empty($rv->salary_above) and empty($rv->salary_below)){
                $rv->salary_above = 'Negotiable';
            }elseif(!empty($rv->salary_above) and empty($rv->salary_below)){
                $rv->salary_above = '￥' . $this->numTostring($rv->salary_above);
            }elseif(empty($value->salary_above) and !empty($rv->salary_below)){
                $rv->salary_above = '￥' . $this->numTostring($rv->salary_below);
            }else{
                $rv->salary_above = '￥' . $this->numTostring($rv->salary_above) . '-' . $this->numTostring($rv->salary_below);
            }
        }


        $favoritesStatus = 0;//职位收藏,默认0
        $contactPhone = '';
        if(!empty($user->uid) and is_numeric($user->uid)){//登录
            $applyJobButton = "applyjob";
            //查看用户状态
            $applyJob = ResumeSend::select('status', 'created_at')->where('job_id', $jobid)->where('personal_uid', $user->uid)
                ->orderBy('created_at', 'desc')->first();//申请职位信息
            $personFavorites = Favorites::where('job_id', $jobid)->where('uid', $user->uid)->first();//收藏信息

            if($personFavorites){//职位收藏
                $favoritesStatus = 1;
            }else{
                $favoritesStatus = 0;
            }

            $favoritesBtton = "personFavorites";
            if($applyJob){//申请职位

                //超过一星期，可以重新投递，当前时间减去创建时间+7
                if(strtotime(date("Y-m-d H:i:s", time())) - strtotime(date("Y-m-d H:i:s", strtotime(' 7 day', strtotime($applyJob->created_at)))) > 0){
                    $applyString = "Reapply position";
                }else{
                    $applyString = "Have post";
                }

            }else{
                $applyString = "Apply position";
            }

            //添加job浏览记录   job_id  personal_uid  resume_id
            $Resume = Resume::select("id")->where("uid", $user->uid)->orderBy("updatetime", "desc")->first();
            if(!empty($Resume->id)){
                if(!BrowseJob::where("job_id", $jobid)->where("personal_uid", $user->uid)->where("resume_id", $Resume->id)->first()){
                    $addBrowseJob = [];
                    $addBrowseJob["company_uid"] = $jobinfo->uid;
                    $addBrowseJob["com_id"] = $jobinfo->com_id;
                    $addBrowseJob["personal_uid"] = $user->uid;
                    $addBrowseJob["resume_id"] = $Resume->id;
                    $addBrowseJob["job_id"] = $jobid;
                    BrowseJob::create($addBrowseJob);
                }
            }

        }else{//未登录

            $applyJobButton = "applyButtonCss personlogin";
            $applyString = "Apply position";

            $favoritesBtton = "personlogin";

            $contactButton = "personlogin";
            $contactHtml = json_encode([]);
        }

        //查询该面试记录是否被查看
        if(!empty($user)){
            $Interview = Interview::where('personal_uid', $user->uid)->where('job_id', $jobid)->where('status', 0)->orderBy('created_at', 'desc')->get();
            if(count($Interview) > 0){
                Interview::where('personal_uid', $user->uid)->where('job_id', $jobid)->update(['status' => 1]);
            }
        }

        //设置县级市
        $jobinfo->company_basic->region = !empty($jobinfo->company_basic->region) ? CollArea::getAreaName($jobinfo->company_basic->region) : '';
        $jobinfo->company_basic->address = $jobinfo->company_basic->region . '/' . $jobinfo->company_basic->address;

        return Style::view('index.english.jobinfo', compact('head_title', 'jobinfo', 'recommendedjob', 'right_jobinfo',
            'photo', 'showphoneconditio', 'applyJobButton', 'favoritesBtton', 'contactButton', 'applyString',
            'favoritesStatus', 'jobid', 'company_id', 'contactInfo', 'contactMobile', 'contactHtml', 'toShareHtml',
            "last_login_time", "resumeRecoveryRate", "to_view"));//
    }

    public function chinese($jobinfo){
        //个人用户登录
        $user = auth()->guard('personal')->user();

        $jobid = $jobinfo->id;

        //查找最近登录时间
        $companyUser = CompanyUser::select('last_login_time', 'viptime')->where('uid', $jobinfo->uid)->first();
        $last_login_time = $this->timediff($companyUser->last_login_time);//timeTranx
        //计算企业回复率
        $allResume = ResumeSend::where("company_uid", $jobinfo->uid)->where("com_id", $jobinfo->com_id)->count();
        $alreadyToCheckResume = ResumeSend::where("company_uid", $jobinfo->uid)->where("com_id", $jobinfo->com_id)->where("status", "!=", 0)->count();

        //算法*  已本看简历/所有简历
        if($allResume == 0){
            $resumeRecoveryRate = '暂无';
        }else{
            $resumeRecoveryRate = (round(($alreadyToCheckResume / $allResume), 2) * 100) . '%';
        }

        $recommendedjob = CompanyJob::with(['company_basic'])
            ->where("com_id", $jobinfo->com_id)
            ->where("job_status", 1)//发布中的职位
            ->orderBy('updatetime', 'desc')->get();//推荐工作

        $right_jobinfo = CompanyJob::with(['company_basic'])->where('job_status', 1)->take(6)->orderBy("urgent", "desc")->get();//该企业其它相关招聘

        $value = $jobinfo;
        $head_title = $value->job_title;
        $company_id = $value->com_id;
        $company_uid = $value->uid;

        //工资
        if(empty($value->salary_above) and empty($value->salary_below)){
            $value->salary_above = '面议';
        }elseif(!empty($value->salary_above) and empty($value->salary_below)){
            $value->salary_above = $this->numTostring($value->salary_above);
        }elseif(empty($value->salary_above) and !empty($value->salary_below)){
            $value->salary_above = $this->numTostring($value->salary_below);
        }else{
            $value->salary_above = $this->numTostring($value->salary_above) . '-' . $this->numTostring($value->salary_below);
        }


        //返回招聘工作地点
        !empty($value->location1) ? $value->location1 = CollArea::getAreaName($value->location1) : $value->location1 = '';
        !empty($value->location2) ? $value->location2 = CollArea::getAreaName($value->location2) : $value->location2 = '';
        !empty($value->location3) ? $value->location3 = CollArea::getAreaName($value->location3) : $value->location3 = '';
        !empty($value->location4) ? $value->location4 = CollArea::getAreaName($value->location4) : $value->location4 = '';
        !empty($value->location5) ? $value->location5 = CollArea::getAreaName($value->location5) : $value->location5 = '';

        $value->location = $value->location1 . ' ' . $value->location2 . ' ' . $value->location3 . ' ' . $value->location4 . ' ' . $value->location5;


        if(trim($value->location) == ''){
            $value->location = "地区不限";
        }

        //返回学历
        $value->education = CollOption::getOptionName($value->education, 'education');
        //返回行业
        $value->industry = CollOption::getOptionName($value->industry, 'industry');
        //返回公司性质
        $value->company_basic->comkind = CollOption::getOptionName($value->company_basic->comkind, 'comkind');
        //规模
        $value->company_basic->employee_num = CollOption::getOptionName($value->company_basic->employee_num, 'employee_num');
        //返回工作时限
        $value->work_year = CollOption::getOptionName($value->work_year, 'work_year');

        //返回时间
        $value->addtime = substr($value->addtime, 0, 10);

        //性别
        if($value->gender == 1){
            $sexvalue = "男";
        }elseif($value->gender == 2){
            $sexvalue = "女";
        }else{
            $sexvalue = '';
        }
        $value->gender = $sexvalue;

        //年龄要求

        if(!empty($value->age_above) and !empty($value->age_below)){
            $value->age = $value->age_above . '岁-' . $value->age_below . '岁';
        }elseif(!empty($value->age_above) and empty($value->age_below)){
            $value->age = $value->age_above . '岁以上';
        }elseif(empty($value->age_above) and !empty($value->age_below)){
            $value->age = $value->age_below . '岁以下';
        }else{
            $value->age = "不限";
        }

        //福利
        $fare = ''; //福利

        if(!empty($value->welfare)){
            $value->welfare = explode(',', $value->welfare);
        }else{
            $value->welfare = array();
        }

        //logo
        if(!empty($value->company_basic->logo)){
            $value->logo = 'upload/companylogo/' . $value->company_basic->logo;
        }else{
            $value->logo = '/default/images/index/default_company_img.jpg';
        }
        //职位发布者信息   0 基本资料 ，1部门，2 独立联系方式，3不显示
        switch($value->contact_info){
            case "0"://0 基本资料
                $phone = explode('-', $value->company_basic->phone);
                if(!empty($phone[0]) && !empty($phone[1])){
                    if(!empty($phone[2])){
                        $value->company_basic->phone = $phone[0] . '-' . $phone[1] . '-' . $phone[2];//有分机号
                    }else{
                        $value->company_basic->phone = $phone[0] . '-' . $phone[1];//无分机号
                    }
                }

                $value->contacts = $value->company_basic->contacts;
                break;
            case "1"://1部门
                $companydepartment = CompanyDepartment::select('name', 'mobile', 'phone', 'contacts')->where('com_id', '=', $value->com_id)->take(1)->get();
                foreach($companydepartment as $cd_v){
                    $value->company_basic->mobile = $cd_v->mobile;

                    if(!empty($cd_v->phone)){
                        $phone = explode('-', $cd_v->phone);
                        if(!empty($phone[0]) && !empty($phone[1])){
                            if(!empty($phone[2])){
                                $value->company_basic->phone = $phone[0] . '-' . $phone[1] . '-' . $phone[2];//有分机号
                            }else{
                                $value->company_basic->phone = $phone[0] . '-' . $phone[1];//无分机号
                            }
                        }
                    }else{
                        $value->company_basic->phone = '';
                    }
                    $value->contacts = $cd_v->contacts;
                    $value->dePartMent = $cd_v->name;
                }

                break;
            case "2"://独立联系方式
                $companycontact = CompanyContact::select('mobile', 'phone', 'contacts')->where('job_id', '=', $value->id)->take(1)->get();
                foreach($companycontact as $cd_v){
                    $value->company_basic->mobile = $cd_v->mobile;
                    $phone = explode('-', $cd_v->phone);
                    if(!empty($phone[0]) && !empty($phone[1])){
                        if(!empty($phone[2])){
                            $value->company_basic->phone = $phone[0] . '-' . $phone[1] . '-' . $phone[2];//有分机号
                        }else{
                            $value->company_basic->phone = $phone[0] . '-' . $phone[1];//无分机号
                        }
                    }
                    $value->contacts = $cd_v->contacts;
                }
                break;
            case "3"://3不显示
                $value->company_basic->mobile = '';
                $value->company_basic->phone = '';
                $value->contacts = '保密';
                break;
        }
        $contactPerson = $value->contacts;
        $contactMobile = $value->company_basic->mobile;
        $contactPhone = $value->company_basic->phone;

        $jobinfo = $value;

        $contactButton = "companyContact ";
        //查看企业方式
        $contactHtml = ['contactPerson' => $contactPerson, 'contactMobile' => $contactMobile, 'contactPhone' => $contactPhone];
        $contactHtml = json_encode($contactHtml);

        //设置联系方式
        $contactInfo = Site::get('view_phone');
        $to_view = '';
        switch($contactInfo){
            case 1:
                $contactMobile = $this->isContactTips($value->company_basic->mobile, $contactPhone, $companyUser);
                break;
            case 2:
                if(auth()->guard('personal')->check()){
                    $contactMobile = $this->isContactTips($value->company_basic->mobile, $contactPhone, $companyUser);
                }else{
                    $contactMobile = $this->hidContact($value->company_basic->mobile, $contactPhone);
                }
                break;
            case 3:
                if(auth()->guard('personal')->check()){
                    $resume = Resume::select('id', 'resume_status')->where('uid', $user->uid)->where('default', 1)->first();//用户简历信息
                }
                if(isset($resume)){
                    $resumeSend = ResumeSend::where('job_id', $jobid)->where('personal_uid', $user->uid)->first();//有无投递记录
                    if(!empty($resumeSend)){
                        $to_view = 1;
                        $contactMobile = $this->isContactTips($value->company_basic->mobile, $contactPhone, $companyUser);
                    }else{
                        $to_view = 2;
                        $contactMobile = $this->hidContact($value->company_basic->mobile, $contactPhone);
                    }
                }else{
                    $to_view = 3;
                    $contactMobile = $this->hidContact($value->company_basic->mobile, $contactPhone);
                    // $contactMobile = "您还没创建简历,不能查看联系方式";
                }
                break;
            default:
                $contactMobile = $this->hidContact($value->company_basic->mobile, $contactPhone);
                break;
        }

        //公司相册
        $photo = CompanyPhoto::select('file', 'remark')->where('com_id', $company_id)->orderBy('updated_at', 'desc')->get()->toArray();

        //返回推荐工作====================================
        foreach($recommendedjob as $value){
            //工资
            if(empty($value->salary_above) and empty($value->salary_below)){
                $value->salary_above = '面议';
            }elseif(!empty($value->salary_above) and empty($value->salary_below)){
                $value->salary_above = $this->numTostring($value->salary_above);
            }elseif(empty($value->salary_above) and !empty($value->salary_below)){
                $value->salary_above = $this->numTostring($value->salary_below);
            }else{
                $value->salary_above = $this->numTostring($value->salary_above) . '-' . $this->numTostring($value->salary_below);
            }

            //返回招聘工作地点
            !empty($value->location1) ? $value->location1 = CollArea::getAreaName($value->location1) : $value->location1 = '';
            !empty($value->location2) ? $value->location2 = CollArea::getAreaName($value->location2) : $value->location2 = '';
            !empty($value->location3) ? $value->location3 = CollArea::getAreaName($value->location3) : $value->location3 = '';
            !empty($value->location4) ? $value->location4 = CollArea::getAreaName($value->location4) : $value->location4 = '';
            !empty($value->location5) ? $value->location5 = CollArea::getAreaName($value->location5) : $value->location5 = '';

            $value->location1 = $value->location1 . ' ' . $value->location2 . ' ' . $value->location3 . ' ' . $value->location4 . ' ' . $value->location5;
            $value->location1 = msubstr($value->location1, 0, 10);
            //返回学历
            !empty($value->education) ? $value->education = CollOption::getOptionName($value->education, 'education') : $value->education = '';

            //返回工作时限
            !empty($value->work_year) ? $value->work_year = CollOption::getOptionName($value->work_year, 'work_year') : $value->work_year = '';

            //返回时间
            !empty($value->addtime) ? $value->addtime = substr($value->addtime, 0, 10) : $value->addtime = '';
            //返回行业

            !empty($value->industry) ? $value->industry = CollOption::getOptionName($value->industry, 'industry') : $value->industry = '';

            //招聘多少人

            !empty($value->company_basic->employee_num) ? $value->employee_num = CollOption::getOptionName($value->company_basic->employee_num, 'employee_num') : '';

            if($value->urgent > date('Y-m-d H:i:s', strtotime('-5 day'))){
                $value->urgent = 1;
            }else{
                $value->urgent = 0;
            }
            //福利
            $fare = ''; //福利
            if(!empty($value->welfare)){
                foreach(explode(',', $value->welfare) as $welfare_value){
                    $fare .= "<i>" . e($welfare_value) . "</i>";
                }
            }
            $value->welfare = $fare;
        }

        //右边企业相关工作$right_jobinfo

        foreach($right_jobinfo as $rv){
            //工资
            if(empty($rv->salary_above) and empty($rv->salary_below)){
                $rv->salary_above = '面议';
            }elseif(!empty($rv->salary_above) and empty($rv->salary_below)){
                $rv->salary_above = '￥' . $this->numTostring($rv->salary_above);
            }elseif(empty($value->salary_above) and !empty($rv->salary_below)){
                $rv->salary_above = '￥' . $this->numTostring($rv->salary_below);
            }else{
                $rv->salary_above = '￥' . $this->numTostring($rv->salary_above) . '-' . $this->numTostring($rv->salary_below);
            }
        }

        $favoritesStatus = 0;//职位收藏,默认0
        $contactPhone = '';
        if(!empty($user->uid) and is_numeric($user->uid)){//登录
            $applyJobButton = "applyjob";
            //查看用户状态
            $applyJob = ResumeSend::select('status', 'created_at')->where('job_id', $jobid)->where('personal_uid', $user->uid)
                ->orderBy('created_at', 'desc')->first();//申请职位信息
            $personFavorites = Favorites::where('job_id', $jobid)->where('uid', $user->uid)->first();//收藏信息

            if($personFavorites){//职位收藏
                $favoritesStatus = 1;
            }else{
                $favoritesStatus = 0;
            }

            $favoritesBtton = "personFavorites";
            if($applyJob){//申请职位

                //超过一星期，可以重新投递，当前时间减去创建时间+7
                if(strtotime(date("Y-m-d H:i:s", time())) - strtotime(date("Y-m-d H:i:s", strtotime(' 7 day', strtotime($applyJob->created_at)))) > 0){
                    $applyString = "重新申请该职位";
                }else{
                    $applyString = "已申请该职位";
                }

            }else{
                $applyString = "申请职位";
            }

            //添加job浏览记录   job_id  personal_uid  resume_id
            $Resume = Resume::select("id")->where("uid", $user->uid)->orderBy("updatetime", "desc")->first();
            if(!empty($Resume->id)){
                if(!BrowseJob::where("job_id", $jobid)->where("personal_uid", $user->uid)->where("resume_id", $Resume->id)->first()){
                    $addBrowseJob = [];
                    $addBrowseJob["company_uid"] = $jobinfo->uid;
                    $addBrowseJob["com_id"] = $jobinfo->com_id;
                    $addBrowseJob["personal_uid"] = $user->uid;
                    $addBrowseJob["resume_id"] = $Resume->id;
                    $addBrowseJob["job_id"] = $jobid;
                    BrowseJob::create($addBrowseJob);
                }
            }

        }else{//未登录

            $applyJobButton = "applyButtonCss personlogin";
            $applyString = "申请职位";

            $favoritesBtton = "personlogin";

            $contactButton = "personlogin";
            $contactHtml = json_encode([]);
        }

        //查询该面试记录是否被查看
        if(!empty($user)){
            $Interview = Interview::where('personal_uid', $user->uid)->where('job_id', $jobid)->where('status', 0)->orderBy('created_at', 'desc')->get();
            if(count($Interview) > 0){
                Interview::where('personal_uid', $user->uid)->where('job_id', $jobid)->update(['status' => 1]);
            }
        }
        //设置县级市
        $jobinfo->company_basic->region = !empty($jobinfo->company_basic->region) ? CollArea::getAreaName($jobinfo->company_basic->region) : '';
        $jobinfo->company_basic->address = $jobinfo->company_basic->region . '/' . $jobinfo->company_basic->address;
        return Style::view('index.jobinfo', compact('head_title', 'jobinfo', 'recommendedjob', 'right_jobinfo',
            'photo', 'showphoneconditio', 'applyJobButton', 'favoritesBtton', 'contactButton', 'applyString',
            'favoritesStatus', 'jobid', 'company_id', 'contactInfo', 'contactMobile', 'contactHtml', 'toShareHtml',
            "last_login_time", "resumeRecoveryRate", "to_view"));//
    }

    /**
     * 联系方式格式化，部分加*
     * @param $mobile
     * @param $contactPhone
     * @return string
     */
    protected function hidContact($mobile, $contactPhone){
        if(empty($mobile) && empty($contactPhone)){
            return '温馨提示:该企业暂不公开联系方式，只接受简历投递!';
        }
        if(!empty($mobile)){
            $mobile = str_replace(substr($mobile, 3, -2), '******', $mobile);
        }
        if(!empty($contactPhone)){
            $contactPhone = str_replace(substr($contactPhone, 3, -2), '******', $contactPhone);
        }
        return trim($mobile . ',' . $contactPhone, ',');
    }

    /**
     * 后台设置来判断普通会员要不要显示联系方式
     * @param $mobile
     * @param $contactPhone
     * @return string
     */
    protected function isContactTips($mobile, $contactPhone, $companyUser){
        if(Site::get('member_contact') == 2 && $companyUser->viptime < date('Y-m-d H:i:s')){
            return '温馨提示:该企业暂不公开联系方式，只接受简历投递!';
        }
        return trim($mobile . ',' . $contactPhone, ',');
    }

    /**
     * 工作详细内容
     * @param $jobid
     * @return mixed
     */
    public function jobinfo($jobid){
        $jobid = idDecryption($jobid);
        $jobinfo = CompanyJob::with(['company_basic'])->where('id', '=', $jobid)->firstOrFail();//当前工作页面详情
        //浏览量增1
        $jobinfo->increment('pageviews');
        if($jobinfo->lang_type == 'en'){
            //职位英文调用
            return $this->english($jobinfo);
        }else{
            //职位中文调用
            return $this->chinese($jobinfo);
        }
    }

    /**
     * 分享朋友圈
     * @param $qrCodeLink
     * @param $head_title
     * @return string
     */
    public function toShare(Request $request){
        if(!empty($request->job_id)){
            $url = url('jobinfo_' . idEncryption($request->job_id) . '.html');
        }elseif(!empty($request->com_id)){
            $url = url('comabout_' . idEncryption($request->com_id) . '.html');
        }else{
            $url = url('/');
        }

        $q = QrCode::format('png')->size(200)->generate($url);
        return response($q, 200, [
            'Content-Type' => 'image/png',
        ]);
    }

    /**
     * 企业介绍画面
     * @param $cid
     * @return mixed
     */
    public function comabout($cid){
        $cid = idDecryption($cid);
        $companyinfo = CompanyBasic::where('id', '=', $cid)->first();//公司信息
        $jobinfo = CompanyJob::with(['company_basic'])->where("com_id", $cid)->where("job_status", 1)->orderBy('updatetime', 'desc')->orderBy('id', 'desc')->paginate(10);//公司其它招聘信息
        $companyUser=auth()->guard('company')->user();
        if((isset($companyinfo) && count($jobinfo) > 0) || auth()->guard('admin')->check()
            || (isset($companyinfo->uid) && isset($companyUser->uid) && $companyinfo->uid==$companyUser->uid)){
            $companyinfo->cn_industry = CollOption::getOptionName($companyinfo->industry, 'industry');//行业
            $companyinfo->cn_comkind = CollOption::getOptionName($companyinfo->comkind, 'comkind');//行业
            $companyinfo->cn_employee_num = CollOption::getOptionName($companyinfo->employee_num, 'employee_num');//行业

            //公司相册
            $photo = CompanyPhoto::select('file', 'remark')->where('com_id', $cid)->orderBy('updated_at', 'desc')->get()->toArray();

            //公司信息
            if(!empty($companyinfo->logo)){
                $companyinfo->logo = asset('upload/companylogo/' . $companyinfo->logo);
            }else{
                $companyinfo->logo = asset('/default/images/index/default_company_img.jpg');
            }

            //福利
            if(!empty($companyinfo->temptation)){
                $companyinfo->temptation = explode(',', $companyinfo->temptation);
            }else{
                $companyinfo->temptation = array();
            }

            //职位发布者=>开关设为0，则直接显示，不跳出登录框提示，开关为1，隐藏联系方式，跳出登录框
            $contactInfo = 1;
            if(auth()->guard('company')->check()){
                $contactInfo = 1;
            }

            $contactButton = "companyContact ";

            switch($contactInfo){
                case 0:

                    if(!empty($companyinfo->phone)){
                        $companyinfo->phone = $companyinfo->phone;
                    }else{
                        $companyinfo->phone = "保密";
                    }

                    break;
                case 1:

                    if(!empty($companyinfo->phone)){
                        $companyinfo->phone = str_replace(substr($companyinfo->phone, 7, 3), '***', $companyinfo->phone);
                    }else{
                        $companyinfo->phone = "保密";
                    }
                    //获取邮箱
                    if(!empty($companyinfo->email)){
                        $companyinfo->email = substr_replace($companyinfo->email, '*****', 3, 5);
                    }else{
                        $companyinfo->email = '';
                    }
                    break;
            }

            //公司其它招聘信息
            foreach($jobinfo as $v){
                //工资
                $v->salary_above = CollOption::getOptionName($v->salary_above, 'expectedsalary');
                $v->salary_below = CollOption::getOptionName($v->salary_below, 'expectedsalary');
                //地区
                !empty($v->location1) ? $v->location1 = ' ' . CollArea::getAreaName($v->location1) : $v->location1 = '';
                !empty($v->location2) ? $v->location2 = ' ' . CollArea::getAreaName($v->location2) : $v->location2 = '';
                !empty($v->location3) ? $v->location3 = ' ' . CollArea::getAreaName($v->location3) : $v->location3 = '';
                !empty($v->location4) ? $v->location4 = ' ' . CollArea::getAreaName($v->location4) : $v->location4 = '';
                !empty($v->location5) ? $v->location5 = ' ' . CollArea::getAreaName($v->location5) : $v->location5 = '';

                $v->location = $v->location1 . ' ' . $v->location2 . ' ' . $v->location3 . ' ' . $v->location4 . ' ' . $v->location5;

                if(trim($v->location) == ''){
                    $v->location = "地区不限";
                }
                //时间
                !empty($v->updatetime) ? $v->updatetime = $this->timediff($v->updatetime) : $v->updatetime = '';
            }
            $sumpage = $jobinfo->lastPage();
            $page = $jobinfo->currentPage();
            //设置上一页、下一页
            $prev = ($page - 1) > 0 ? $page - 1 : 1;
            $next = ($page + 1) < $sumpage ? $page + 1 : $sumpage;

            $user = auth()->guard('personal')->user();
            if(auth()->guard('personal')->check()){//登录

                //添加job浏览记录   job_id  personal_uid  resume_id
                $Resume = Resume::select("id")->where("uid", $user->uid)->orderBy("updatetime", "desc")->first();
                if(!empty($Resume->id)){
                    if(!BrowseCompany::where("com_id", $cid)->where("personal_uid", $user->uid)->where("resume_id", $Resume->id)->first()){
                        $addBrowseCompany = [];
                        $addBrowseCompany["company_uid"] = $companyinfo->uid;
                        $addBrowseCompany["com_id"] = $companyinfo->id;
                        $addBrowseCompany["personal_uid"] = $user->uid;
                        $addBrowseCompany["resume_id"] = $Resume->id;
                        BrowseCompany::create($addBrowseCompany);
                    }
                }

            }else{//未登录
            }
            return Style::view('index.comabout', compact('head_title', 'companyinfo', 'jobinfo', 'photo', 'company_status', 'prev', 'next', 'page', 'sumpage'));//接收企业ID号
        }else{
            abort(404);
        }
    }

    /**
     * ajax 分页操作
     * @param Request $request
     * @return string
     */
    public function handle_ajax(Request $request){
        $count = CompanyJob::with(['company_basic'])->where("com_id", $request->companyid)->where("job_status", 1)->count();//有多少条信息
        $pagenum = 10;//每页显示多少个
        $sumpage = ceil($count / $pagenum);
        $page = (!empty($request->page)) ? $request->page : 1;
        //设置上一页、下一页
        $prev = ($page - 1) > 0 ? $page - 1 : 1;
        $next = ($page + 1) < $sumpage ? $page + 1 : $sumpage;
        //求偏移量
        $offset = ($page - 1) * $pagenum;

        $jobinfo = CompanyJob::with(['company_basic'])->where("com_id", $request->companyid)->where("job_status", 1)->orderBy('updatetime', 'desc')
            ->orderBy('id', 'desc')->skip($offset)->take($pagenum)->get();//公司其它招聘信息
        //公司其它招聘信息
        foreach($jobinfo as $v){
            //工资
            $v->salary_above = CollOption::getOptionName($v->salary_above, 'expectedsalary');
            $v->salary_below = CollOption::getOptionName($v->salary_below, 'expectedsalary');
            //地区
            !empty($v->location1) ? $v->location1 = ' ' . CollArea::getAreaName($v->location1) : $v->location1 = '';
            !empty($v->location2) ? $v->location2 = ' ' . CollArea::getAreaName($v->location2) : $v->location2 = '';
            !empty($v->location3) ? $v->location3 = ' ' . CollArea::getAreaName($v->location3) : $v->location3 = '';
            !empty($v->location4) ? $v->location4 = ' ' . CollArea::getAreaName($v->location4) : $v->location4 = '';
            !empty($v->location5) ? $v->location5 = ' ' . CollArea::getAreaName($v->location5) : $v->location5 = '';
            $v->location = $v->location1 . ' ' . $v->location2 . ' ' . $v->location3 . ' ' . $v->location4 . ' ' . $v->location5;
            if(trim($v->location) == ''){
                $v->location = "地区不限";
            }
            //时间
            !empty($v->updatetime) ? $v->updatetime = $this->timediff($v->updatetime) : $v->updatetime = '';
        }
        return Style::view('layouts.companyAbout', compact('jobinfo', 'prev', 'next', 'page', 'sumpage'));
    }

    /**
     * 万转数字
     * @param $num
     * @return float
     */
    private function floatNum($num){
        $float_num = floatval($num);
        $explode_float_num = explode('.', $float_num);
        if(!empty($explode_float_num[1])){
            $float_num = $explode_float_num[0] * 10000;
        }elseif(!empty($explode_float_num[0]) and strlen($explode_float_num[0]) <= 2){
            $float_num = $float_num * 10000;
        }
        return $float_num;
    }

    /**
     * 数字转万
     * @param $num
     * @return string
     */
    public function numTostring($num){
        $numstring = '';
        if(!empty($num)){
            if(strlen($num) >= 5){
                $numstring = floatval($num / 10000) . '万';
            }else{
                return $num;
            }
        }
        return $numstring;
    }

    /**
     * 返回时间差
     * @param $time
     * @return string
     */
    public function timediff($time){
        return timeTran($time);
    }

    /**
     * 职位站点
     * @param Request $request
     * @return mixed
     */
    public function stationJob(Request $request){
        //获取当前URL域名地址
        $url = getUrl();
        //默认主站的标识和编号
        $station_cid = '';
        $station = AreaStation::
        where(function($query) use ($url){
            if(!empty($url)){
                $query->orWhere('station_domain', '=', $url)
                    ->orWhere('station_domain', '=', $url . '/');
            }
        })
            ->first();
        if(!empty($station)){
            $station_name = $station->station_name;
            $station_cid = $station->station_cid;
        }

        //获取职位列表
        $jobList = DB::table('company_job as t1')
            ->join('company_basic as t2', 't1.com_id', '=', 't2.id')
            ->select('t1.id', 't1.com_id', 't1.job_title', 't1.urgent',
                't1.location1', 't1.location2', 't1.location3', 't1.location4', 't1.location5',
                't1.salary_above', 't1.salary_below', 't1.education', 't1.work_year', 't1.updatetime', 't2.company_name')
            //工作地点(某个地区下)
            ->where(function($query) use ($station_cid){
                if(!empty($station_cid)){
                    $query->orWhere('t1.location1', '=', $station_cid)
                        ->orWhere('t1.location2', '=', $station_cid)
                        ->orWhere('t1.location3', '=', $station_cid)
                        ->orWhere('t1.location4', '=', $station_cid)
                        ->orWhere('t1.location5', '=', $station_cid);
                }
            })//岗位
            ->where(function($query) use ($request){
                if(!empty($request->jobsort1)){
                    $query->orWhere('t1.job_category1', '=', $request->jobsort1)
                        ->orWhere('t1.job_category2', '=', $request->jobsort1)
                        ->orWhere('t1.job_category3', '=', $request->jobsort1)
                        ->orWhere('t1.job_category4', '=', $request->jobsort1)
                        ->orWhere('t1.job_category5', '=', $request->jobsort1);
                }
            })
            //职位显示审核通过的
            ->where('t1.job_status', '1');
        //设置自定分页
        $count = $jobList->count();
        $jobList = $jobList->orderBy('t1.updatetime', 'desc')
            ->orderBy('t1.id', 'desc')
            ->skip($this->getSkip($request->page))->take(20)->get();
        $jobList = $this->pageInfo($jobList, $count, $request);

        foreach($jobList as $v){
            $v->joburl = 'jobinfo_' . idEncryption($v->id) . '.html';
            $v->comurl = 'comabout_' . idEncryption($v->com_id) . '.html';
            $v->salary_above = !empty($v->salary_above) ? CollOption::getOptionName($v->salary_above, 'expectedsalary') : '';
            $v->salary_below = !empty($v->salary_below) ? CollOption::getOptionName($v->salary_below, 'expectedsalary') : '';
            $v->money = ($v->salary_above) ? $v->salary_above . '~' . $v->salary_below : '面议';
            $location1 = !empty($v->location1) ? CollArea::getAreaName($v->location1) : '';
            $location2 = !empty($v->location2) ? CollArea::getAreaName($v->location2) : '';
            $location3 = !empty($v->location3) ? CollArea::getAreaName($v->location3) : '';
            $location4 = !empty($v->location4) ? CollArea::getAreaName($v->location4) : '';
            $location5 = !empty($v->location5) ? CollArea::getAreaName($v->location5) : '';
            $v->location = trim($location1 . ',' . $location2 . ',' . $location3 . ',' . $location4 . ',' . $location5, ',');
            $v->work_year = !empty($v->work_year) ? CollOption::getOptionName($v->work_year, 'work_year') : '';
            $v->education = !empty($v->education) ? CollOption::getOptionName($v->education, 'education') : '';
            $v->updatetime = substr($v->updatetime, 0, 10);
            //急聘
            if($v->urgent > date('Y-m-d H:i:s', strtotime('-5 day'))){
                $v->urgent = 1;
            }else{
                $v->urgent = 0;
            }
        }
        return Style::view('index.stationJob', compact('jobList', 'station_name', 'station_cid', 'station'));
    }

    /**
     * 分页信息
     */
    protected function pageInfo($data, $total, $request){
        $perPage = 20;//每页显示20条
        $current_page = $request->input('page', 1);
        $total = $total > 4000 ? 4000 : $total;
        $company_job = new LengthAwarePaginator($data, $total, $perPage, $current_page, [
            'path' => Paginator::resolveCurrentPath(), //注释2
            'pageName' => 'page',
        ]);
        return $company_job;
    }

    /**
     * 取得分页启始数
     */
    protected function getSkip($page){
        if(empty($page)) $page = 1;
        if($page > 200) $page = 200;
        return ($page - 1) * 20;
    }

    /**
     * app下载
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    //m 微信类型（chat） id 当前的职位ID 当前用户的 token随机值
    //http://www.15hr.com/aap_code?m=chat&id=65464&t=SDKJFDSFHKSD
    public function appDown(Request $request){
        $user = auth()->guard('personal')->user();
        if(!empty($user)){
            if(empty($user->api_token)){
                $user->api_token = str_random(60);
                $user->save();
            }
            $token = $user->api_token;
        }else{
            $token = '';
        }
        $url = asset('app_code?m=chat&id=' . $request->job_id . '&t=' . $token);
        $q = QrCode::format('png')->size(320)->generate($url);
        return response($q, 200, [
            'Content-Type' => 'image/png',
        ]);
    }

    /**
     * app下载
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    //m 微信类型（chat） id 当前的职位ID 当前用户的 token随机值
    //http://www.15hr.com/aap_code?m=chat&id=65464&t=SDKJFDSFHKSD
    public function appCompanyDown(Request $request){
        $user = auth()->guard('personal')->user();
        if(!empty($user)){
            if(empty($user->api_token)){
                $user->api_token = str_random(60);
                $user->save();
            }
            $token = $user->api_token;
        }else{
            $token = '';
        }

        $url = asset('app_code?m=code&id=' . $request->com_id . '&t=' . $token);
        $q = QrCode::format('png')->size(320)->generate($url);
        return response($q, 200, [
            'Content-Type' => 'image/png',
        ]);
    }

}

